package cn.dinkevin.xui.net.exception;


import cn.dinkevin.xui.ErrorInfo;

/**
 * Create with Android Studio
 * Author: chengpengfei
 * Date: 2018/5/6
 * Time: 11:13 AM
 * Description:
 */
public class ApiException extends RuntimeException {

    private int code;
    private String msg;
    private String displayMessage;

    public ApiException(int code) {
        this.code = code;
        this.msg = this.displayMessage = ErrorInfo.getMessage(code);
    }

    public ApiException(int code, String msg) {
        this.code = code;
        this.msg = msg;
        this.displayMessage = ErrorInfo.getMessage(code);
    }

    public ApiException(BizException bizException) {
        this.code = bizException.getCode();
        this.msg = bizException.getMessage();
        this.displayMessage = ErrorInfo.getMessage(code);
    }

    public int getCode() {
        return code;
    }

    @Override
    public String getMessage() {
        return msg;
    }

    public String getDisplayMessage() {
        return displayMessage;
    }


    @Override
    public String toString() {
        return "ApiException{" +
                "code=" + code +
                ", msg='" + msg + '\'' +
                ", displayMessage='" + displayMessage + '\'' +
                '}';
    }
}
